//
//  MWTreeSeedCell.m
//  XiRan-iOS
//
//  Created by liuyiming on 2019/12/4.
//  Copyright © 2019 Wood. All rights reserved.
//

#import "MWTreeSeedCell.h"

@interface MWTreeSeedCell ()

@property(nonatomic, strong) UIView *containerView;
@property(nonatomic, strong) UIImageView *pictureIV;
@property(nonatomic, strong) UILabel *titleLB;
@property(nonatomic, strong) UILabel *descLB;

@end

@implementation MWTreeSeedCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (!(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
        return nil;
    }

    [self setupPageSubviews];
    [self layoutPageSubviews];
    
    return self;
}

- (void)setupData:(MWTreeSeed *)model {
    NSString *urlStr = [NSString stringWithFormat:@"%@?x-oss-process=image/resize,h_210", model.image];
    [_pictureIV sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:[UIImage imageNamed:@"infoIcon"]];
    
    _titleLB.text = model.title;
    _descLB.text = model.intro;
}

- (void)setupPageSubviews {
    _containerView = [[UIView alloc] init];
    _containerView.backgroundColor = [UIColor whiteColor];
    _containerView.layer.cornerRadius = 5;
    _containerView.layer.masksToBounds = YES;
    [self.contentView addSubview:_containerView];
    
    _pictureIV = [[UIImageView alloc] init];
    _pictureIV.contentMode = UIViewContentModeScaleAspectFit;
    _pictureIV.layer.cornerRadius = 5;
    _pictureIV.layer.masksToBounds = YES;
    [_containerView addSubview:_pictureIV];
    
    _titleLB = [[UILabel alloc] init];
    _titleLB.numberOfLines = 1;
    _titleLB.font = MWFont(15);
    _titleLB.textColor = MWHexColor(@"#333333");
    [_containerView addSubview:_titleLB];
    
    _descLB = [[UILabel alloc] init];
    _descLB.numberOfLines = 2;
    _descLB.font = MWFont(12);
    _descLB.textColor = MWHexColor(@"#666666");
    [_containerView addSubview:_descLB];
}

- (void)layoutPageSubviews {
    [_containerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(16);
        make.right.equalTo(self.contentView).offset(-16);
        make.height.equalTo(@105);
    }];
    
    [_pictureIV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.containerView).offset(16);
        make.centerY.equalTo(self.containerView);
        make.width.height.equalTo(@70);
    }];
    
    [_titleLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.pictureIV).offset(5);
        make.left.equalTo(self.pictureIV.mas_right).offset(12);
        make.right.equalTo(self.containerView.mas_right).offset(-12);
    }];
    
    [_descLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLB.mas_bottom).offset(10);
        make.left.equalTo(self.pictureIV.mas_right).offset(12);
        make.right.equalTo(self.containerView.mas_right).offset(-12);
    }];
}


@end
